package v;

import c.MedicoController;
import core.constructor.constructor;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.commons.lang3.StringEscapeUtils;
import tools.DatosComboBox;
import tools.Util;

/**
 *
 * @author !gaso
 */
//si se va agregar una entidad eliminada previamente, no funciona.
//verificar esa parte
public class Medico_View_Add extends javax.swing.JPanel {

    constructor c;
    MedicoController controller = new MedicoController();
    DatosComboBox cbx;
    //Modo en que se debe de desplegar la Interfaz - INSERT - UPDATE - SELECT
    private String mod = "";
    private String llavePrimaria;
    //Corresponde al Nombre del Campo en la Base de Datos que es LlavePrimaria
    private String campoPK;
    private String noIdentificacion = "";

    public Medico_View_Add(Object... e) {
        initComponents();

        config(e);
        //prepararTransaccion();


    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        cIdentificacion = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        cNombres = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        cApellidos = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        cTelefono1 = new javax.swing.JTextField();
        cTelefono2 = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        cEmail = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        cbEstado = new javax.swing.JComboBox();
        cbDepto = new javax.swing.JComboBox();
        bGuardar = new javax.swing.JButton();
        bClear = new javax.swing.JButton();
        bCancelar = new javax.swing.JButton();
        jXTitledSeparator1 = new org.jdesktop.swingx.JXTitledSeparator();
        jXTitledSeparator2 = new org.jdesktop.swingx.JXTitledSeparator();
        jXTitledSeparator3 = new org.jdesktop.swingx.JXTitledSeparator();
        cbCiudad = new javax.swing.JComboBox();
        jLabel10 = new javax.swing.JLabel();
        cbEspecialidad = new javax.swing.JComboBox();
        cbTipo = new javax.swing.JComboBox();
        cDireccion = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();

        setMinimumSize(new java.awt.Dimension(403, 371));

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel1.setText("Numero Identificación");

        cIdentificacion.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel2.setText("Nombres");

        cNombres.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        jLabel3.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel3.setText("Apellidos");

        cApellidos.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        jLabel4.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel4.setText("Telefono 1");

        cTelefono1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        cTelefono2.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        jLabel5.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel5.setText("Telefono 2");

        jLabel6.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel6.setText("Correo electronico");

        jLabel7.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel7.setText("Depto Residencia");

        jLabel8.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel8.setText("Especialidad");

        cEmail.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        jLabel9.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel9.setText("Estado");

        cbEstado.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        cbDepto.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        cbDepto.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cbDeptoItemStateChanged(evt);
            }
        });
        cbDepto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbDeptoActionPerformed(evt);
            }
        });

        bGuardar.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        bGuardar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/core/img/guardar32.png"))); // NOI18N
        bGuardar.setText("Guardar");
        bGuardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bGuardarActionPerformed(evt);
            }
        });

        bClear.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        bClear.setIcon(new javax.swing.ImageIcon(getClass().getResource("/core/img/limpiar32.png"))); // NOI18N
        bClear.setText("Limpiar Campos");
        bClear.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bClearActionPerformed(evt);
            }
        });

        bCancelar.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        bCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/core/img/cancelar32.png"))); // NOI18N
        bCancelar.setText("Cancelar");
        bCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bCancelarActionPerformed(evt);
            }
        });

        jXTitledSeparator1.setFont(new java.awt.Font("Tahoma", 1, 15)); // NOI18N
        jXTitledSeparator1.setHorizontalTextPosition(javax.swing.SwingConstants.LEADING);
        jXTitledSeparator1.setTitle("Datos Generales");

        jXTitledSeparator2.setFont(new java.awt.Font("Tahoma", 1, 15)); // NOI18N
        jXTitledSeparator2.setHorizontalTextPosition(javax.swing.SwingConstants.LEADING);
        jXTitledSeparator2.setTitle("Datos Ubicación");

        jXTitledSeparator3.setFont(new java.awt.Font("Tahoma", 1, 15)); // NOI18N
        jXTitledSeparator3.setHorizontalTextPosition(javax.swing.SwingConstants.LEADING);
        jXTitledSeparator3.setTitle("Otros Datos");

        cbCiudad.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        jLabel10.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel10.setText("Ciudad Residencia");

        cbEspecialidad.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        cbTipo.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        cDireccion.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        jLabel12.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel12.setText("Direccion");

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
                        .add(jLabel1)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(cIdentificacion, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 174, Short.MAX_VALUE)
                        .add(18, 18, 18)
                        .add(cbTipo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 154, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(jXTitledSeparator1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .add(layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jLabel2)
                            .add(jLabel3))
                        .add(87, 87, 87)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(cApellidos)
                            .add(org.jdesktop.layout.GroupLayout.TRAILING, cNombres)))
                    .add(org.jdesktop.layout.GroupLayout.LEADING, jXTitledSeparator2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jLabel9)
                            .add(jLabel6)
                            .add(jLabel8))
                        .add(35, 35, 35)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(cbEspecialidad, 0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .add(cEmail)
                            .add(cbEstado, 0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                    .add(org.jdesktop.layout.GroupLayout.LEADING, jXTitledSeparator3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jLabel7)
                            .add(jLabel10))
                        .add(31, 31, 31)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(cbDepto, 0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .add(cbCiudad, 0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                    .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jLabel5)
                            .add(jLabel4)
                            .add(jLabel12))
                        .add(76, 76, 76)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(cDireccion)
                            .add(org.jdesktop.layout.GroupLayout.TRAILING, cTelefono2)
                            .add(cTelefono1))))
                .addContainerGap())
            .add(layout.createSequentialGroup()
                .add(45, 45, 45)
                .add(bGuardar)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(bClear)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(bCancelar)
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(jXTitledSeparator1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel1)
                    .add(cIdentificacion, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(cbTipo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 23, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel2)
                    .add(cNombres, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(cApellidos, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel3))
                .add(21, 21, 21)
                .add(jXTitledSeparator2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(12, 12, 12)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(jLabel4)
                        .add(12, 12, 12)
                        .add(jLabel5))
                    .add(layout.createSequentialGroup()
                        .add(cTelefono1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(cTelefono2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(4, 4, 4)
                        .add(jLabel12)
                        .add(0, 0, Short.MAX_VALUE))
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                        .add(cDireccion, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(cbDepto, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(jLabel7))))
                .add(13, 13, 13)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jLabel10)
                    .add(cbCiudad, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jXTitledSeparator3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(3, 3, 3)
                        .add(jLabel6)
                        .add(9, 9, 9)
                        .add(jLabel8)
                        .add(14, 14, 14)
                        .add(jLabel9))
                    .add(layout.createSequentialGroup()
                        .add(cEmail, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(4, 4, 4)
                        .add(cbEspecialidad, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(cbEstado, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                .add(18, 18, 18)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(bGuardar)
                    .add(bClear)
                    .add(bCancelar))
                .add(34, 34, 34))
        );
    }// </editor-fold>//GEN-END:initComponents

private void bGuardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bGuardarActionPerformed
    prepararTransaccion();
}//GEN-LAST:event_bGuardarActionPerformed

private void cbDeptoItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cbDeptoItemStateChanged
    //Evento que afecta Combobox de Ciudades iniciado por ComboBox Departamentos
    cbCiudad.setModel(new javax.swing.DefaultComboBoxModel(cbx.cbCiudad(cbDepto)));
}//GEN-LAST:event_cbDeptoItemStateChanged

    private void cbDeptoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbDeptoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_cbDeptoActionPerformed

    private void bClearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bClearActionPerformed
        // TODO add your handling code here:
        Util.limpiarCamposForm(this);
    }//GEN-LAST:event_bClearActionPerformed

    private void bCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bCancelarActionPerformed
        if (c != null) {
            c.ventPrincipal();
        } else {
            Logger.getLogger(Acudiente_View_Add.class.getName()).log(Level.WARNING, "La Clase Constructor no ha sido instanciada");
        }
    }//GEN-LAST:event_bCancelarActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton bCancelar;
    private javax.swing.JButton bClear;
    private javax.swing.JButton bGuardar;
    private javax.swing.JTextField cApellidos;
    private javax.swing.JTextField cDireccion;
    private javax.swing.JTextField cEmail;
    private javax.swing.JTextField cIdentificacion;
    private javax.swing.JTextField cNombres;
    private javax.swing.JTextField cTelefono1;
    private javax.swing.JTextField cTelefono2;
    private javax.swing.JComboBox cbCiudad;
    private javax.swing.JComboBox cbDepto;
    private javax.swing.JComboBox cbEspecialidad;
    private javax.swing.JComboBox cbEstado;
    private javax.swing.JComboBox cbTipo;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private org.jdesktop.swingx.JXTitledSeparator jXTitledSeparator1;
    private org.jdesktop.swingx.JXTitledSeparator jXTitledSeparator2;
    private org.jdesktop.swingx.JXTitledSeparator jXTitledSeparator3;
    // End of variables declaration//GEN-END:variables

    /**
     * <strong>config</strong><br> Configura los parametros que provienen del
     * constructor de la clase.<br> e[0] - contiene el JFrame 'padre'.</br> e[1]
     * - Modo de Presentacion de la Interfaz (INSERT / UPDATE / SELECT).</br>
     * e[2] - contiene el JFrame 'padre'.</br>
     *
     * @param e
     */
    private void config(Object... e) {
        if (e.length > 0) {
            try {
                c = (constructor) e[0];

                cbx = new DatosComboBox();
                llenarCombos();

                //Configura la Interfaz para el Modo en el que fue invocado
                configModo((String) e[1], (String) e[2]);
              
                //Setear Migas de Pan
                c.setNavegar("Medico_View_Grid");
                // Indicar a las 'migas de pan' donde estamos.
                c.setLabelModulo("Medicos");

            } catch (Exception exc) {
                System.err.println("(config())Error de Asignacion , compruebe el numero de Parametros que envia .. " + exc.getMessage());
                exc.printStackTrace();
            }
        }
    }

    private void llenarCombos() {
        cbDepto.setModel(new javax.swing.DefaultComboBoxModel(cbx.cbDepartamento()));
        cbDepto.setSelectedItem("Valle del Cauca");
        cbCiudad.setModel(new javax.swing.DefaultComboBoxModel(cbx.cbCiudad(cbDepto)));
        cbEstado.setModel(new javax.swing.DefaultComboBoxModel(cbx.cbEstado()));
        cbEstado.setSelectedItem("ACTIVO");
        cbEspecialidad.setModel(new javax.swing.DefaultComboBoxModel(cbx.cbEspecialidad()));
        cbTipo.setModel(new javax.swing.DefaultComboBoxModel(cbx.cbTipoDocumento()));
    }

    private void prepararTransaccion() {

        //Herramientas
        tools.Util u = new tools.Util();

        String tablaBD = "medico";
//        
//        tabla = "identificacion=55[req-num(0,20)]";

        StringBuilder sqlAndRestricciones = new StringBuilder();

        sqlAndRestricciones.append("Numero Identificacion@identificacion='" + cIdentificacion.getText().toLowerCase() + "'[req-num(6,10)UNQ" + noIdentificacion + "]&");
        sqlAndRestricciones.append("Tipo documento@id_tipodocumento='" + cbx.getKeyTipoDocumento(cbTipo) + "'[req-(0,0)]&");
        sqlAndRestricciones.append("Nombre Medico@nombres='" + cNombres.getText().toLowerCase() + "'[req-txt(0,30)]&");
        sqlAndRestricciones.append("Apellido Medico@apellidos='" + cApellidos.getText().toLowerCase() + "'[req-txt(0,40)]&");
        sqlAndRestricciones.append("Telefono 1@telefono1='" + cTelefono1.getText().toLowerCase() + "'[-num(7,15)]&");
        sqlAndRestricciones.append("Telefono 2@telefono2='" + cTelefono2.getText().toLowerCase() + "'[-num(7,15)]&");
        sqlAndRestricciones.append("Direccion@direccion='" + StringEscapeUtils.escapeEcmaScript(cDireccion.getText().toLowerCase()) + "'[-(0,120)&]");
        sqlAndRestricciones.append("Ciudad@id_ciudad='" + cbx.getKeyMun(cbCiudad) + "'[req-(0,0)]&");
        sqlAndRestricciones.append("Especialidad@id_especialidad='" + cbx.getKeyEspecialidad(cbEspecialidad) + "'[req-(0,0)]&");
        sqlAndRestricciones.append("Estado@estado='" + cbx.getKeyEstado(cbEstado) + "'[req-(0,0)]&");
        sqlAndRestricciones.append("Correo@email='" + cEmail.getText().toLowerCase() + "'[-mail(0,40)]");

        String mensajeUsuario = controller.prepararTransaccion(tablaBD, sqlAndRestricciones, mod, "El Medico", campoPK);

        c.informarUsuario(mensajeUsuario);
    }

    private void configModo(String m, String key) {
        mod = m;

//        String SQL_BUSCAR = String.format("SELECT identificacion, nombres, apellidos, "
//                + "telefono1, telefono2, id_ciudad, email, id_especialidad, "
//                + "id_estado, id_tipodocumento, direccion "
//                + "FROM medico WHERE id_medico = '%s' ", key);


        String SQL_BUSCAR = String.format("SELECT identificacion, nombres, apellidos, "
                + "telefono1, telefono2, id_ciudad, email, id_especialidad, "
                + "estado, id_tipodocumento, direccion "
                + "FROM medico WHERE id_medico = '%s' ", key);

        if (!mod.equals("")) {
            
            if("INSERT".equals(mod)){
                c.setLabelAccion("Ingresar Nuevo Médico");
            }

            if (!mod.equals("INSERT")) {
                setLlavePrimaria(key);
                //c.setLabelAccion("Crear Acudiente Paciente");
                campoPK = "id_medico = " + getLlavePrimaria();
            }

            if (mod.equals("SELECT")) {
                System.out.println("mod = " + mod);
                System.out.println("key = " + key);
                estadoComponentes(false);
                c.setLabelAccion("Consulta Médico");
                setMedico(controller.buscar(SQL_BUSCAR));

            } else if (mod.equals("UPDATE")) {
                System.out.println("mod = " + mod);
                System.out.println("key = " + key);

                estadoComponentes(true);

                c.setLabelAccion("Modificar Médico");
                setMedico(controller.buscar(SQL_BUSCAR));
                bGuardar.setText("Actualizar");
                //Cambiar icono here...

                //Tomar cuando arranque la pantalla los campos UNQ
                noIdentificacion = cIdentificacion.getText();
                System.out.println("noIdentificacion = " + noIdentificacion);
            }
        }
    }

    public String getLlavePrimaria() {
        return llavePrimaria;
    }

    public void setLlavePrimaria(String llavePrimaria) {
        this.llavePrimaria = llavePrimaria;
    }

    void estadoComponentes(Boolean estado) {
        cIdentificacion.setEditable(estado);
        cNombres.setEditable(estado);
        cApellidos.setEditable(estado);
        cTelefono1.setEditable(estado);
        cTelefono2.setEditable(estado);
        cbDepto.setEnabled(estado);
        cbCiudad.setEnabled(estado);
        cEmail.setEditable(estado);
        cbEspecialidad.setEnabled(estado);
        cbTipo.setEnabled(estado);
        cbEstado.setEnabled(estado);
        bGuardar.setVisible(estado);
        bClear.setVisible(estado);
    }

    private void setMedico(Object[][] medico) {

        System.out.println("Tamaño medico " + medico.length);
        cIdentificacion.setText(medico[0][0].toString());
        cNombres.setText(medico[0][1].toString());
        cApellidos.setText(medico[0][2].toString());
        cTelefono1.setText(medico[0][3].toString());
        cTelefono2.setText(medico[0][4].toString());
        cbDepto.setSelectedItem(cbx.getValueDpto(medico[0][5].toString()));
        cbCiudad.setSelectedItem(cbx.getValueCiudad(medico[0][5].toString()));
        cEmail.setText(medico[0][6].toString());
        cbEspecialidad.setSelectedItem(cbx.getValueEsp(medico[0][7].toString()));
        cbEstado.setSelectedItem(cbx.getValueEstado(medico[0][8].toString()));
        cbTipo.setSelectedItem(cbx.getValueTipoDoc(medico[0][9].toString()));
        cDireccion.setText(medico[0][10].toString());
    }
}